<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="流程名称" prop="processName">
        <el-input
          v-model="queryParams.processName"
          placeholder="请输入流程名称"
          clearable
        />
      </el-form-item>
      <el-form-item label="接收时间">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="YYYY-MM-DD HH:mm:ss"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="defaultTime"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        <el-button
          type="primary"
          plain
          icon="el-icon-download"
          v-hasPermi="['workflow:process:claimExport']"
          @click="handleExport"
          >导出</el-button
        >
        <el-button
          type="primary"
          plain
          icon="el-icon-edit"
          :disabled="single"
          @click="handleClaim()"
          >签收
        </el-button>
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="claimList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" />
      <el-table-column
        label="任务编号"
        prop="taskId"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="流程名称" prop="procDefName" />
      <el-table-column label="任务节点" prop="taskName" />
      <el-table-column label="流程版本">
        <template #default="scope">
          <el-tag>v{{ scope.row.procDefVersion }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="流程发起人">
        <template #default="scope">
          <label
            >{{ scope.row.startUserName }}
            <el-tag type="info">{{ scope.row.startDeptName }}</el-tag></label
          >
        </template>
      </el-table-column>
      <el-table-column label="接收时间" prop="createTime" width="180" />
      <!-- <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template #default="scope">
          v-hasPermi="['workflow:process:claim']"
          <el-button
            type="text"
            icon="el-icon-s-claim"
            @click="handleClaim(scope.row)"
            >签收
          </el-button>
        </template>
      </el-table-column> -->
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script name="Claim" setup>
import { listClaimProcess } from '@/api/workflow/process'
import { claimTask } from '@/api/workflow/task'
import { useRoute, useRouter } from 'vue-router'
const router = useRouter()
const { proxy } = getCurrentInstance()
const data = reactive({
  // 遮罩层
  loading: true,
  // 选中数组
  ids: [],
  // 非单个禁用
  single: true,
  // 非多个禁用
  multiple: true,
  // 显示搜索条件
  showSearch: true,
  // 总条数
  total: 0,
  // 流程待办任务表格数据
  claimList: [],
  // 弹出层标题
  title: '',
  // 是否显示弹出层
  open: false,
  // 日期范围
  dateRange: [],
  // 查询参数
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    name: null,
    processName: null
  },
  // 表单参数
  form: {},
  // 表单校验
  rules: {}
})
const {
  // 遮罩层
  loading,
  // 选中数组
  ids,
  // 非单个禁用
  single,
  // 非多个禁用
  multiple,
  // 显示搜索条件
  showSearch,
  // 总条数
  total,
  // 流程待办任务表格数据
  claimList,
  // 弹出层标题
  title,
  // 是否显示弹出层
  open,
  // 日期范围
  dateRange,
  // 查询参数
  queryParams,
  // 表单参数
  form,
  // 表单校验
  rules
} = toRefs(data)
const defaultTime = ref([
  new Date(2000, 1, 1, 0, 0, 0),
  new Date(2000, 2, 1, 23, 59, 59)
])
// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.taskId)
  single.value = selection.length !== 1
  multiple.value = !selection.length
}
/** 查询流程定义列表 */
function getList() {
  loading.value = true
  listClaimProcess(proxy.addDateRange(queryParams.value, dateRange.value)).then(
    response => {
      claimList.value = response.rows
      total.value = response.total
      loading.value = false
    }
  )
}
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}
/** 重置按钮操作 */
function resetQuery() {
  dateRange.value = []
  proxy.resetForm('queryForm')
  handleQuery()
}
/** 签收 */
function handleClaim(row) {
  claimTask({ taskId: row ? row.taskId : ids.value.toString() }).then(
    response => {
      proxy.$modal.msgSuccess('操作成功')
      router.push({
        path: '/process/myTodo'
      })
    }
  )
}
/** 导出按钮操作 */
function handleExport() {
  proxy.downLoadByUrl(
    'bpmn/workflow/process/claimExport',
    {
      ...queryParams.value
    },
    `wf_claim_process_${new Date().getTime()}.xlsx`
  )
}
getList()
</script>

<style scoped></style>
